package top.suven.base.http.admin.sec.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.suven.base.core.mybatis.PageData;
import top.suven.base.http.admin.sec.dao.AdminRoleDao;
import top.suven.base.http.admin.sec.model.AdminRole;
import top.suven.base.http.admin.sec.service.AdminRoleService;
import top.suven.base.http.admin.sec.vo.response.AdminRoleResponseVo;
import top.suven.base.http.enums.EnableStatusEnum;
import top.suven.base.util.utilize.BeanUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Title: AdminRoleService.java
 * @Description: 操作员角色关系的业务处理服务类
 * @author lixiangling
 * @date   2018/08/13 17:07:07
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
@Component("adminRoleService")
public class AdminRoleServiceImpl implements AdminRoleService {
    private final static Logger logger = LoggerFactory.getLogger(AdminRoleServiceImpl.class);
    @Autowired
    private AdminRoleDao adminRoleDao;
    /**
     * @Title: 获取操作员角色关系分页信息
     * @Description:
     * @param adminRole @{Link AdminRole}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 17:07:07
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public PageData<AdminRoleResponseVo> getAdminRolePage(AdminRole adminRole, int start, int pageSize){
        int count = adminRoleDao.countEntity(adminRole);
        if(count == 0){
            return new PageData<AdminRoleResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<AdminRole> adminRoleList = adminRoleDao.findPageEntity(adminRole, start, pageSize);
        if(adminRoleList == null || adminRoleList.isEmpty()){
            return new PageData<AdminRoleResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<AdminRoleResponseVo> adminRoleResponseList = adminRoleList.stream().map(adminRoleResponse -> {
            AdminRoleResponseVo adminRoleResponseVo = new AdminRoleResponseVo();
            BeanUtil.copyProperties(adminRoleResponse, adminRoleResponseVo);
            return adminRoleResponseVo;
        }).collect(Collectors.toList());
        return new PageData<AdminRoleResponseVo>(adminRoleResponseList,count);
    }
    /**
     * @Title: 获取操作员角色关系列表信息
     * @Description:
     * @param adminRole @{Link AdminRole}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 17:07:07
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public List<AdminRole> getAdminRoleList(AdminRole adminRole){
        return adminRoleDao.findEntity(adminRole);
    }

    /**
     * @Title: 新增操作员角色关系信息
     * @Description:
     * @param adminRole @{Link AdminRole}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 17:07:07
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void addAdminRole(AdminRole adminRole){
        adminRoleDao.createEntity(adminRole);
    }
    /**
    * @Title: 修改操作员角色关系信息
    * @Description:
    * @param adminRole @{Link AdminRole}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 17:07:07
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void updAdminRole(AdminRole adminRole){
        adminRoleDao.updateEntity(adminRole);
    }
   /**
    * @Title: 获取操作员角色关系信息
    * @Description:
    * @param id @{Link Long}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 17:07:07
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public AdminRole getAdminRole(Long id){
        AdminRole adminRole = new AdminRole();
        adminRole.setAdminRoleId(id);
        return adminRoleDao.retrieveEntity(adminRole);
    }
    /**
     * @Title: 删除操作员角色关系信息
     * @Description:
     * @param ids @{Link Long[]}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 17:07:07
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void del(Long[] ids){
        adminRoleDao.del(Arrays.asList(ids));
    }
   /**
    * @Title: 启用操作员角色关系信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 17:07:07
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOn(Long[] ids){
        adminRoleDao.updateEnableStatus(EnableStatusEnum.ENABLE.getIndexStr(), Arrays.asList(ids));
    }
   /**
    * @Title: 禁用操作员角色关系信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/13 17:07:07
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOff(Long[] ids){
        adminRoleDao.updateEnableStatus(EnableStatusEnum.DISABLE.getIndexStr(), Arrays.asList(ids));
    }
}